<%--
  Created by IntelliJ IDEA.
  User: 王辉
  Date: 2022/5/10
  Time: 19:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<% request.setCharacterEncoding("UTF-8");%>
<html>
<head>
    <title>恢复数据</title>
</head>
<body>
<%
    String driverName="com.mysql.cj.jdbc.Driver";
    String username = "root";
    String password = "123456";
    String url = "jdbc:mysql://localhost:3306/t_card?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false";
    Class.forName(driverName);
    Connection conn = DriverManager.getConnection(url,username,password);
    String sql = "update cuser set isdeleted = 0 where cid = ?";
    Integer cid = Integer.parseInt(request.getParameter("cid"));
    String sql2 = "select id from user where username = ?";
    PreparedStatement pstmt1 = conn.prepareStatement(sql);
    PreparedStatement pstmt2 = conn.prepareStatement(sql2);
    String userName = (String) session.getAttribute("username");
    pstmt2.setString(1,userName);
    ResultSet rs1 = pstmt2.executeQuery();
    String uid = "";
    while (rs1.next()){
        uid = rs1.getString("id");
    }
    pstmt1.setInt(1,cid);
    int result = pstmt1.executeUpdate();
    if(result==1){
%>
<div align="center"><h1 style="color: crimson">恢复成功</h1><br><br>
    <a href="index.jsp" style="color: chartreuse">返回主页</a><br><br><br>
    <a href="recycle.jsp.jsp" style="color: crimson">返回回收站</a><br><br><br>
</div>

<%
}else{
%>
<div align="center"><h1 style="color: crimson">恢复失败</h1><br><br>
    <a href="index.jsp" style="color: chartreuse">返回主页</a><br><br><br>
    <a href="recycle.jsp.jsp" style="color: crimson">返回回收站</a><br><br><br>
</div>
<%
    }
%>
</body>
</html>
